var t = require;
var e = module;
var o = exports;
var _n7,
    i =
        (this && this.__extends) ||
        ((_n7 = function n(t, e) {
            return (_n7 =
                Object.setPrototypeOf ||
                ({ __proto__: [] }
                    instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) {
                        Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                    }
                })(t, e);
        }),
            function (t, e) {
                function o() {
                    this.constructor = t;
                }
                _n7(t, e), (t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o()));
            }),
    s =
        (this && this.__decorate) ||
        function (t, e, o, n) {
            var i,
                s = arguments.length,
                r = s < 3 ? e : null === n ? (n = Object.getOwnPropertyDescriptor(e, o)) : n;
            if (
                "object" == (typeof Reflect === "undefined" ? "undefined" : typeof Reflect) &&
                "function" == typeof Reflect.decorate
            )
                r = Reflect.decorate(t, e, o, n);
            else
                for (var c = t.length - 1; c >= 0; c--) {
                    (i = t[c]) && (r = (s < 3 ? i(r) : s > 3 ? i(e, o, r) : i(e, o)) || r);
                }
            return s > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", { value: !0 });
var r = t("Global"),
    c = t("SDK"),
    a = t("Common"),
    u = t("UIManager"),
    l = t("UIEnum"),
    d = t("BlockItem"),
    p = t("TextItem"),
    h = t("IndexUI"),
    f = t("ResourceManager"),
    g = cc._decorator,
    y = g.ccclass,
    m = g.property,
    v = (function (t) {
        function e() {
            var e = (null !== t && t.apply(this, arguments)) || this;
            return (
                (e.indexUI = null),
                (e.lvLabel = null),
                (e.shilingNode = null),
                (e.itemsNode = null),
                (e.slotNode = null),
                (e.textsNode = null),
                (e.textsBgNode = null),
                (e.tempTexts = null),
                (e.randomsNode = null),
                (e.removesNode = null),
                (e.tipsCountLabel = null),
                (e.tipsBtn = null),
                (e.topUI = null),
                (e.blockItemPrefab = null),
                (e.textPrefab = null),
                (e.chapters = null),
                (e.texts = null),
                (e.languages = null),
                (e.bgmMusic = null),
                (e.successMusic = null),
                (e.failMusic = null),
                (e.numberToTexts = {}),
                (e.currentLanguages = 0),
                (e.chapterInfo = null),
                (e._status = 0),
                (e._zanting = !1),
                (e.gameConfig = null),
                (e.totalBlockNum = 0),
                (e.totalTextNum = 0),
                (e.currentTextNum = 0),
                (e.allBlocks = []),
                (e.slotArea = []),
                (e.opHistory = []),
                (e.chessBoard = []),
                (e.boxWidthNum = 19),
                (e.boxHeightNum = 19),
                (e.currSlotNum = 0),
                (e.textX = -350),
                (e.commonSoundId = 0),
                (e.gameTime = 0),
                (e.gameWaitTime = 0),
                (e.tipsWaitTime = 0),
                (e.tipsDurningTime = 2),
                (e.tipsScale = !1),
                (e.tipsScaleTime = 0),
                (e.hasTips = !1),
                (e.currentChapter = 0),
                (e.lastPopTime = 0),
                (e.tipsCount = 0),
                (e.useXiPai = !1),
                (e.useCheHui = !1),
                (e.useYiChu = !1),
                (e.useShengShou = !1),
                (e.openShengShou = !1),
                (e.useTouShi = !1),
                (e.useFuhuo = !1),
                (e.useWenquxing = !1),
                (e.initChessBoard = function (t, o) {
                    e.chessBoard = new Array(t);
                    for (var n = 0; n < t; n++) {
                        e.chessBoard[n] = new Array(o);
                        for (var i = 0; i < o; i++) {
                            e.chessBoard[n][i] = { blocks: [] };
                        }
                    }
                }),
                (e.initGame = function () {
                    if (0 == e.currentChapter) {
                        e.gameConfig = {
                            slotNum: 7,
                            typeNum: 3,
                            levelBlockNum: 9,
                            borderStep: 1,
                            levelNum: 1,
                            randomBlocks: [0, 0],
                            animals: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
                        };
                        var t = (20 * Math.random()) >> 0;
                        e.chapterInfo = e.chapters.json[t];
                    } else
                        1 == e.currentChapter ?
                            ((e.gameConfig = {
                                slotNum: 7,
                                typeNum: 14,
                                levelBlockNum: 50,
                                borderStep: 1,
                                levelNum: 7,
                                randomBlocks: [11, 11],
                                animals: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
                            }),
                                (e.chapterInfo = e.chapters.json[21])) :
                            2 == e.currentChapter ?
                                ((e.gameConfig = {
                                    slotNum: 7,
                                    typeNum: 14,
                                    levelBlockNum: 60,
                                    borderStep: 1,
                                    levelNum: 7,
                                    randomBlocks: [11, 11],
                                    animals: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
                                }),
                                    (e.chapterInfo = e.chapters.json[22])) :
                                3 == e.currentChapter &&
                                ((e.gameConfig = {
                                    slotNum: 7,
                                    typeNum: 14,
                                    levelBlockNum: 60,
                                    borderStep: 1,
                                    levelNum: 10,
                                    randomBlocks: [11, 11],
                                    animals: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
                                }),
                                    (e.chapterInfo = e.chapters.json[23]));
                    e.loadNumberToTextDir(), (e.allBlocks = []);
                    for (
                        var o = e.gameConfig.randomBlocks.reduce(function (t, e) {
                            return t + e;
                        }, 0),
                        n = [],
                        i = e.chapterInfo.cs,
                        s = [],
                        r = 0; r < i.length; r++
                    ) {
                        for (var c = i[r], a = 0; a < e.texts.json.length; a++) {
                            if ((v = e.texts.json[a].text) == c) {
                                s.push(a);
                                break;
                            }
                        }
                    }
                    var u = s,
                        l = 700 / u.length;
                    l < 22 && (l = 22);
                    var d = l / 2 - 350,
                        h = 0,
                        f = Math.ceil(u.length / 30),
                        g = 0;
                    for (
                        1 == f ?
                            ((h = 0),
                                (g = 0),
                                (e.itemsNode.scale = 1),
                                (e.itemsNode.y = 60),
                                (e.textsBgNode.height = 200)) :
                            2 == f ?
                                ((h = 20),
                                    (g = 40),
                                    (e.itemsNode.scale = 1),
                                    (e.itemsNode.y = 60),
                                    (e.textsBgNode.height = 200)) :
                                3 == f ?
                                    ((h = 35),
                                        (g = 35),
                                        (e.itemsNode.scale = 1),
                                        (e.itemsNode.y = 60),
                                        (e.textsBgNode.height = 200)) :
                                    4 == f ?
                                        ((h = 40),
                                            (g = 28),
                                            (e.itemsNode.scale = 1),
                                            (e.itemsNode.y = 60),
                                            (e.textsBgNode.height = 200)) :
                                        5 == f ?
                                            ((h = 60),
                                                (g = 30),
                                                (e.itemsNode.scale = 1),
                                                (e.itemsNode.y = 60),
                                                (e.textsBgNode.height = 200)) :
                                            6 == f ?
                                                ((h = 60),
                                                    (g = 25),
                                                    (e.itemsNode.scale = 1),
                                                    (e.itemsNode.y = 60),
                                                    (e.textsBgNode.height = 200)) :
                                                7 == f ?
                                                    ((h = 66),
                                                        (g = 22),
                                                        (e.itemsNode.scale = 1),
                                                        (e.itemsNode.y = 60),
                                                        (e.textsBgNode.height = 200)) :
                                                    8 == f ?
                                                        ((h = 70),
                                                            (g = 20),
                                                            (e.itemsNode.scale = 1),
                                                            (e.itemsNode.y = 60),
                                                            (e.textsBgNode.height = 200)) :
                                                        ((e.itemsNode.scale = 0.9),
                                                            (e.itemsNode.y = 30),
                                                            (e.textsBgNode.height = 260),
                                                            (h = 70),
                                                            (g = 20)),
                        e.totalBlockNum = 0,
                        r = 0; r < u.length; r++
                    ) {
                        var y = cc.instantiate(e.textPrefab);
                        if (
                            ((y.x = d),
                                (y.y = h),
                                e.textsNode.addChild(y),
                                y.getComponent(p.default).init(e, u[r], i[r]),
                                l < 75)
                        ) {
                            var m = l / 75;
                            y.getComponent(p.default).textLabel.fontSize = 75 * m;
                        }
                        (d += l), (r + 1) % 32 == 0 && ((h -= g), (d = l / 2 - 350));
                        var v = e.texts.json[u[r]];
                        for (a = 0; a < v.ps.length; a++) {
                            n.push(v.ps[a]), e.totalBlockNum++;
                        }
                    }
                    for (e.totalTextNum = u.length, e.currentTextNum = e.totalTextNum, r = 0; r < o; r++) {
                        var _ = (Math.random() * n.length) >> 0,
                            S = n[_];
                        n.splice(_, 1), n.push(S);
                    }
                    var b = n.reverse();
                    for (r = 0; r < e.totalBlockNum; r++) {
                        var A = { id: r, status: 0, level: 0, type: b[r], higherThanBlocks: [], lowerThanBlocks: [] };
                        e.allBlocks.push(A);
                    }
                    var w = 0,
                        I = [];
                    e.gameConfig.randomBlocks.forEach(function (t, o) {
                        I[o] = [];
                        for (var n = 0; n < t; n++) {
                            I[o].push(e.allBlocks[w]), w++;
                        }
                    });
                    var T = e.totalBlockNum - o,
                        N = [],
                        k = e.gameConfig.levelNum,
                        B = e.boxWidthNum - e.gameConfig.levelNum,
                        C = e.gameConfig.levelNum,
                        O = e.boxHeightNum - e.gameConfig.levelNum;
                    for (r = 0; r < e.gameConfig.levelNum; r++) {
                        var x = Math.min(e.gameConfig.levelBlockNum, T);
                        r == e.gameConfig.levelNum - 1 && (x = T),
                            e.gameConfig.borderStep > 0 &&
                            ((k -= e.gameConfig.borderStep),
                                (B += e.gameConfig.borderStep),
                                (C -= e.gameConfig.borderStep),
                                (O += e.gameConfig.borderStep),
                                k < 0 && (k = 0),
                                B > e.boxWidthNum && (B = e.boxWidthNum),
                                C < 0 && (C = 0),
                                O > e.boxHeightNum && (O = e.boxHeightNum));
                        var R = e.shuffle(e.allBlocks.slice(w, w + x));
                        if ((N.push.apply(N, R), (w += x), e.genLevelBlockPos(R, k, C, B, O), (T -= x) <= 0)) break;
                    }
                    return { levelBlocks: N, randomBlocks: I, slotArea: [] };
                }),
                (e.genLevelBlockPos = function (t, o, n, i, s) {
                    var r = [],
                        c = [],
                        a = 0,
                        u = 0;
                    if (e.currentChapter > 0) {
                        for (var l = o; l < i; l++) {
                            for (var d = n; d < s; d++) {
                                if (a % 3 == 0 && u % 3 == 0) {
                                    var p = { x: l, y: d };
                                    r.push(p);
                                }
                                u++;
                            }
                            a++;
                        }
                        c = e.shuffle(r);
                    } else
                        r.push({ x: 3, y: 6 }),
                            r.push({ x: 6, y: 6 }),
                            r.push({ x: 9, y: 6 }),
                            r.push({ x: 12, y: 6 }),
                            r.push({ x: 15, y: 6 }),
                            r.push({ x: 15, y: 9 }),
                            r.push({ x: 15, y: 12 }),
                            r.push({ x: 15, y: 15 }),
                            r.push({ x: 12, y: 9 }),
                            r.push({ x: 12, y: 12 }),
                            r.push({ x: 12, y: 15 }),
                            r.push({ x: 9, y: 9 }),
                            r.push({ x: 9, y: 12 }),
                            r.push({ x: 9, y: 15 }),
                            r.push({ x: 6, y: 9 }),
                            r.push({ x: 6, y: 12 }),
                            r.push({ x: 6, y: 15 }),
                            r.push({ x: 3, y: 9 }),
                            r.push({ x: 3, y: 12 }),
                            r.push({ x: 3, y: 15 }),
                            (c = r);
                    var h = new Set();
                    for (l = 0; l < t.length; l++) {
                        for (
                            var f = t[l], g = void 0, y = void 0, m = void 0; c.length > 0 ?
                                ((g = (p = c.shift()).x), (y = p.y)) :
                                ((g = Math.floor(Math.random() * i + o)), (y = Math.floor(Math.random() * s + n))),
                            (m = g + "," + y),
                            h.has(m);

                        ) { }
                        h.add(m), (f.x = g), (f.y = y), e.genLevelRelation(f), e.chessBoard[g][y].blocks.push(f);
                    }
                }),
                (e.genLevelRelation = function (t) {
                    for (
                        var o = Math.max(t.x - 2, 0),
                        n = Math.max(t.y - 2, 0),
                        i = Math.min(t.x + 3, e.boxWidthNum),
                        s = Math.min(t.y + 3, e.boxHeightNum),
                        r = 0,
                        c = o; c < i; c++
                    ) {
                        for (var a = n; a < s; a++) {
                            var u = e.chessBoard[c][a].blocks;
                            if (u.length > 0) {
                                var l = u[u.length - 1];
                                if (l.id === t.id) continue;
                                (r = Math.max(r, l.level)), t.higherThanBlocks.push(l), l.lowerThanBlocks.push(t);
                            }
                        }
                    }
                    t.level = r + 1;
                }),
                e
            );
        }
        return (
            i(e, t),
            (e.prototype.onLoad = function () {
                var t = this;
                c.default.init(),
                    r.default.init(),
                    f.ResourceMgr.init(),
                    u.UIMgr.setUILayer(this.node.getChildByName("UI")),
                    this.indexUI.init(this),
                    (this.lastPopTime = new Date().getTime()),
                    c.default.isAndroid() &&
                    (this.currentLanguages = jsb.reflection.callStaticMethod(
                        "org/cocos2dx/javascript/AppActivity",
                        "getLanguage",
                        "()I"
                    )),
                    c.default.isIOS() &&
                    (this.currentLanguages = jsb.reflection.callStaticMethod("FCTool", "getLanguage")),
                    1 == r.default.settings.music && a.default.playMusic(this.bgmMusic, !0),
                    c.default.isAndroid() && 0 == this.currentLanguages ?
                        ((this.shilingNode.active = !0),
                            this.shilingNode.on(
                                cc.Node.EventType.TOUCH_END,
                                function () {
                                    u.UIMgr.show(l.default.ShilingUI, t, !1);
                                },
                                this
                            )) :
                        (this.shilingNode.active = !1),
                    // c.default.isKS() && 
                    u.UIMgr.show(l.default.SplashUI, this, !1);
            }),
            (e.prototype.loadNumberToTextDir = function () {
                for (var t = this.chapterInfo.cs, e = 0; e < t.length; e++) {
                    for (var o = t[e], n = 0; n < this.texts.json.length; n++) {
                        var i = this.texts.json[n];
                        if (i.text == o) {
                            var s = i.ps;
                            if (s.length > 1) {
                                var r = s[0] + "-" + s[1],
                                    c = s[1] + "-" + s[0];
                                (this.numberToTexts[r] = n), (this.numberToTexts[c] = n);
                            } else {
                                var a = s[0] + "";
                                this.numberToTexts[a] = n;
                            }
                            break;
                        }
                    }
                }
            }),
            (e.prototype.shuffle = function (t) {
                for (var e, o = []; t.length > 0;) {
                    (e = Math.floor(Math.random() * t.length)), o.push(t[e]), t.splice(e, 1);
                }
                return o;
            }),
            (e.prototype.tips = function () {
                for (var t = [], e = [], o = this.itemsNode.children, n = 0; n < o.length; n++) {
                    (i = o[n].getComponent(d.default)).blockType.lowerThanBlocks.length <= 0 && t.push(i.blockType),
                        1 == i.blockType.lowerThanBlocks.length && e.push(i.blockType);
                }
                for (n = 0; n < this.removesNode.children.length; n++) {
                    var i = this.removesNode.children[n].getComponent(d.default);
                    t.push(i.blockType);
                }
                if (this.randomsNode.children[0].childrenCount > 0) {
                    var s = this.randomsNode.children[0].children[this.randomsNode.children[0].childrenCount - 1];
                    t.push(s.getComponent(d.default).blockType);
                }
                for (
                    this.randomsNode.children[1].childrenCount > 0 &&
                    ((s = this.randomsNode.children[1].children[this.randomsNode.children[1].childrenCount - 1]),
                        t.push(s.getComponent(d.default).blockType)),
                    t = t.concat(this.slotArea),
                    n = 0; n < t.length; n++
                ) {
                    for (var r = 0; r < t.length; r++) {
                        if (n != r) {
                            var c = t[n].type + "-" + t[r].type,
                                a = this.numberToTexts[c],
                                u = this.getTextNodeByIdx(a);
                            if (a >= 0 && u) return t[n].blockItem.tips(), void t[r].blockItem.tips();
                            var l = t[r].type + "-" + t[n].type;
                            if (((a = this.numberToTexts[l]), (u = this.getTextNodeByIdx(a)), a >= 0 && u))
                                return t[n].blockItem.tips(), void t[r].blockItem.tips();
                        }
                    }
                }
                for (n = 0; n < t.length; n++) {
                    for (r = 0; r < e.length; r++) {
                        if (
                            ((c = t[n].type + "-" + e[r].type),
                                (a = this.numberToTexts[c]),
                                (u = this.getTextNodeByIdx(a)),
                                a >= 0 && u)
                        )
                            return t[n].blockItem.tips(), void e[r].blockItem.tips();
                        if (
                            ((l = e[r].type + "-" + t[n].type),
                                (a = this.numberToTexts[l]),
                                (u = this.getTextNodeByIdx(a)),
                                a >= 0 && u)
                        )
                            return t[n].blockItem.tips(), void e[r].blockItem.tips();
                    }
                }
                for (n = 0; n < t.length; n++) {
                    var p = t[n].type + "";
                    if (((a = this.numberToTexts[p]), (u = this.getTextNodeByIdx(a)), a >= 0 && u))
                        return void t[n].blockItem.tips();
                }
                for (n = 0; n < e.length; n++) {
                    if (e.length > 1) {
                        var h = n >= e.length - 1 ? 0 : n + 1;
                        if (
                            ((c = e[n].type + "-" + e[h].type),
                                (a = this.numberToTexts[c]),
                                (u = this.getTextNodeByIdx(a)),
                                a >= 0 && u)
                        )
                            return e[n].blockItem.tips(), void e[h].blockItem.tips();
                        var f = 0 == n ? e.length - 1 : n - 1;
                        if (
                            ((l = e[n].type + "-" + e[f].type),
                                (a = this.numberToTexts[l]),
                                (u = this.getTextNodeByIdx(a)),
                                a >= 0 && u)
                        )
                            return e[n].blockItem.tips(), void e[f].blockItem.tips();
                    }
                }
            }),
            (e.prototype.wenquxing = function () {
                var t = this,
                    e = new Date().getTime();
                (this.lastPopTime = e),
                    (this.gameWaitTime = 0),
                    c.default.isWeb() || ((this.useWenquxing = !0), (this.indexUI.wenquBtn.active = !1)),
                    this.indexUI.doWenquxing(function () {
                        t.opHistory = [];
                        for (
                            var e = (10 * Math.random() + 10) >> 0,
                            o = function o() {
                                for (
                                    var e = t.allBlocks.filter(function (t) {
                                        return 0 === t.status && 16 != t.type && 180 != t.type;
                                    }),
                                    o = (Math.random() * e.length) >> 0,
                                    n = e[o],
                                    i = -1,
                                    s = null,
                                    r = null,
                                    c = function c(o) {
                                        var c = e[o];
                                        if (n.id != c.id) {
                                            var a = !1,
                                                u = n.type + "-" + c.type,
                                                l = c.type + "-" + n.type;
                                            if (
                                                ((i = t.numberToTexts[u]),
                                                    (r = t.getTextNodeByIdx(i)),
                                                    i >= 0 && r ?
                                                        ((s = t.texts.json[i]), (a = !0)) :
                                                        ((i = t.numberToTexts[l]),
                                                            (r = t.getTextNodeByIdx(i)),
                                                            i >= 0 && r && ((s = t.texts.json[i]), (a = !0))),
                                                    a)
                                            ) {
                                                (r.getComponent(p.default).status = 1),
                                                    (n.status = 2),
                                                    (c.status = 2),
                                                    n.blockItem.removeBindHigher(),
                                                    c.blockItem.removeBindHigher();
                                                var d = n.blockItem.node.parent.convertToWorldSpaceAR(
                                                    n.blockItem.node.position
                                                ),
                                                    h = t.textsNode.convertToNodeSpaceAR(d);
                                                (n.blockItem.node.parent = t.tempTexts),
                                                    (n.blockItem.node.position = h),
                                                    (n.blockItem.bgNode.active = !1),
                                                    (n.blockItem.tipsNode.active = !1),
                                                    (n.blockItem.lockNode.active = !1);
                                                var f = cc.v3(0, -830, 0),
                                                    g = f.x - 30,
                                                    y = f.y;
                                                cc.tween(n.blockItem.node)
                                                    .to(0.4, { x: g, y: y })
                                                    .to(0.2, { position: f })
                                                    .call(function () {
                                                        var e = cc.instantiate(t.textPrefab);
                                                        e.getComponent(p.default).init(t, i, s.text),
                                                            e.getComponent(p.default).light(),
                                                            t.tempTexts.addChild(e),
                                                            e.setPosition(f),
                                                            cc
                                                                .tween(e)
                                                                .delay(0.2)
                                                                .to(0.5, { position: r.position })
                                                                .call(function () {
                                                                    r.getComponent(p.default).light(),
                                                                        e.destroy();
                                                                })
                                                                .start(),
                                                            n.blockItem.node.destroy();
                                                    })
                                                    .start();
                                                var m = c.blockItem.node.parent.convertToWorldSpaceAR(
                                                    c.blockItem.node.position
                                                ),
                                                    v = t.textsNode.convertToNodeSpaceAR(m);
                                                (c.blockItem.node.parent = t.tempTexts),
                                                    (c.blockItem.node.position = v),
                                                    (c.blockItem.bgNode.active = !1),
                                                    (c.blockItem.tipsNode.active = !1),
                                                    (c.blockItem.lockNode.active = !1);
                                                var _ = f.x + 30,
                                                    S = f.y;
                                                return (
                                                    cc
                                                        .tween(c.blockItem.node)
                                                        .to(0.4, { x: _, y: S })
                                                        .to(0.2, { position: f })
                                                        .call(function () {
                                                            c.blockItem.node.destroy();
                                                        })
                                                        .start(),
                                                    (t.totalBlockNum -= 2),
                                                    t.currentTextNum--,
                                                    t.totalBlockNum <= 0 && t.success(),
                                                    "break"
                                                );
                                            }
                                        }
                                    },
                                    a = 0; a < e.length && "break" !== c(a); a++
                                ) { }
                            },
                            n = 0; n < e; n++
                        ) {
                            o();
                        }
                    });
            }),
            (e.prototype.xipai = function () {
                var t = this.allBlocks.filter(function (t) {
                    return 0 === t.status;
                }),
                    e = this.shuffle(
                        t.map(function (t) {
                            return t.type;
                        })
                    ),
                    o = 0;
                t.forEach(function (t) {
                    (t.type = e[o++]),
                        cc
                            .tween(t.blockItem.node)
                            .to(0.5, { x: 0, y: 0 })
                            .by(0.5, { angle: 360 })
                            .delay(0.2)
                            .call(function () {
                                t.blockItem.loadInfo(!0);
                            })
                            .start();
                }),
                    (this.useXiPai = !0);
            }),
            (e.prototype.undo = function () {
                var t = this,
                    e = this.opHistory.pop();
                if (e) {
                    this.useCheHui = !0;
                    for (var o = 0; o < this.slotArea.length; o++) {
                        if (this.slotArea[o].id == e.id) {
                            this.slotArea.splice(o, 1);
                            break;
                        }
                    }
                    if ((this.currSlotNum--, (e.status = 0), 0 == e.blockItem.position)) {
                        var n = 30 * e.x - 270,
                            i = 300 - 30 * e.y,
                            s = cc.v3(n, i, 0),
                            r = this.itemsNode.convertToWorldSpaceAR(s),
                            c = this.slotNode.convertToNodeSpaceAR(r);
                        cc.tween(e.blockItem.node)
                            .to(0.5, { position: c })
                            .call(function () {
                                (e.blockItem.node.parent = t.itemsNode), e.blockItem.loadInfo(!1);
                            })
                            .start();
                    } else if (1 == e.blockItem.position) {
                        var a = this.randomsNode.children[e.x],
                            u = a.children[a.children.length - 1];
                        (e.blockItem.node.parent = a),
                            e.blockItem.loadInfo(!1),
                            u &&
                            (u.getComponent(d.default).blockType.lowerThanBlocks.push(e),
                                u.getComponent(d.default).reload(),
                                e.higherThanBlocks.push(u.getComponent(d.default).blockType));
                    } else
                        2 == e.blockItem.position &&
                            ((e.blockItem.node.y = 0), (e.blockItem.node.parent = this.removesNode));
                    this.reloadSlot(-1);
                }
            }),
            (e.prototype.yichu = function (t) {
                var e = this;
                if (this.slotArea.length > 0) {
                    t && (this.useYiChu = !0), (this.opHistory = []);
                    for (
                        var o = function o() {
                            var t = n.slotArea.pop();
                            if ((n.currSlotNum--, t)) {
                                var o = n.removesNode.parent.convertToWorldSpaceAR(n.removesNode.getPosition()),
                                    i = n.slotNode.convertToNodeSpaceAR(o);
                                cc
                                    .tween(t.blockItem.node)
                                    .to(0.5, { x: i.x, y: i.y })
                                    .call(function () {
                                        (t.blockItem.node.y = 0), (t.blockItem.node.parent = e.removesNode);
                                    })
                                    .start(),
                                    (t.blockItem.position = 2),
                                    (t.status = 0);
                            }
                        },
                        n = this,
                        i = 0; i < 3; i++
                    ) {
                        o();
                    }
                }
            }),
            (e.prototype.shengshou = function () {
                (this.useShengShou = !0), (this.openShengShou = !0);
                for (var t = this.itemsNode.children, e = 0; e < t.length; e++) {
                    t[e].getComponent(d.default).lockNode.active = !1;
                }
            }),
            (e.prototype.closeShengShou = function () {
                this.openShengShou = !1;
                for (var t = this.itemsNode.children, e = 0; e < t.length; e++) {
                    t[e].getComponent(d.default).reload();
                }
            }),
            (e.prototype.toushi = function () {
                c.default.isWeb() ? (this.tipsCount += 10) : (this.tipsCount += 5),
                    (this.tipsCountLabel.string = this.tipsCount + "");
            }),
            (e.prototype.initChapter = function () {
                c.default.startRecorder(),
                    this.slotNode.destroyAllChildren(),
                    this.textsNode.destroyAllChildren(),
                    this.itemsNode.destroyAllChildren(),
                    this.removesNode.destroyAllChildren(),
                    this.indexUI.showChapter(),
                    (this.currSlotNum = 0),
                    (this.tipsDurningTime = 2),
                    (this._status = 1),
                    (this.textX = -350),
                    (this.gameTime = 0),
                    (this.tipsCount = 2),
                    (this.useCheHui = !1),
                    (this.useShengShou = !1),
                    (this.useTouShi = !1),
                    (this.useXiPai = !1),
                    (this.useYiChu = !1),
                    (this.useFuhuo = !1),
                    (this.useWenquxing = !1),
                    c.default.isWeb() ? (this.indexUI.wenquBtn.active = !0) : (this.indexUI.wenquBtn.active = !1),
                    this.initChessBoard(this.boxWidthNum, this.boxHeightNum);
                var t = this.initGame(),
                    e = t.levelBlocks,
                    o = t.randomBlocks;
                (this.slotArea = t.slotArea), (this.tipsCountLabel.string = this.tipsCount + "");
                for (var n = 0; n < e.length; n++) {
                    var i = e[n];
                    (a = cc.instantiate(this.blockItemPrefab)).getComponent(d.default).init(this, 0, i),
                        this.itemsNode.addChild(a);
                }
                for (n = 0; n < o.length; n++) {
                    var s = o[n];
                    this.randomsNode.children[n].destroyAllChildren();
                    for (var r = 0; r < s.length; r++) {
                        var a,
                            u = s[r];
                        (u.x = n),
                            (u.y = r),
                            s[r + 1] && (u.lowerThanBlocks.push(s[r + 1]), s[r + 1].higherThanBlocks.push(u)),
                            (a = cc.instantiate(this.blockItemPrefab)).getComponent(d.default).init(this, 1, u),
                            this.randomsNode.children[n].addChild(a);
                    }
                }
                this.sendEvent("startChapter");
            }),
            (e.prototype.reloadSlot = function (t) {
                for (var e = 0; e < this.slotArea.length; e++) {
                    var o = this.slotArea[e];
                    o.id != t &&
                        cc
                            .tween(o.blockItem.node)
                            .to(0.2, { x: 90 * e + 45 })
                            .start();
                }
            }),
            (e.prototype.checkClear = function () {
                var t = this,
                    e = -1,
                    o = null,
                    n = null;
                if (this.slotArea.length > 1)
                    for (var i = 0; i < this.slotArea.length; i++) {
                        for (var s = !1, c = 0; c < this.slotArea.length; c++) {
                            if (this.slotArea[i].id != this.slotArea[c].id) {
                                var a = this.slotArea[i].type + "-" + this.slotArea[c].type;
                                if (
                                    (e = this.numberToTexts[a]) >= 0 &&
                                    ((o = this.texts.json[e]), (n = this.getTextNodeByIdx(e)))
                                ) {
                                    s = !0;
                                    break;
                                }
                                var u = this.slotArea[c].type + "-" + this.slotArea[i].type;
                                if (
                                    (e = this.numberToTexts[u]) >= 0 &&
                                    ((o = this.texts.json[e]), (n = this.getTextNodeByIdx(e)))
                                ) {
                                    s = !0;
                                    break;
                                }
                            }
                        }
                        if (s) break;
                        var l = this.slotArea[i].type + "";
                        if (
                            (e = this.numberToTexts[l]) >= 0 &&
                            ((o = this.texts.json[e]), (n = this.getTextNodeByIdx(e)))
                        )
                            break;
                    }
                else
                    1 == this.slotArea.length &&
                        ((l = this.slotArea[0].type + ""),
                            (e = this.numberToTexts[l]) >= 0 && ((o = this.texts.json[e]), (n = this.getTextNodeByIdx(e))));
                if (n) {
                    (this.opHistory = []), (n.getComponent(p.default).status = 1);
                    var d = o.ps,
                        h = function h(i) {
                            f.currSlotNum--;
                            var s = d[i],
                                r = f.getBlockTypeByType(f.slotArea, s),
                                c = f.slotArea[r];
                            (c.status = 2), f.slotArea.splice(r, 1);
                            var a = c.blockItem,
                                u = a.node.parent.convertToWorldSpaceAR(a.node.position),
                                l = f.textsNode.convertToNodeSpaceAR(u);
                            (a.node.parent = f.tempTexts), (a.node.position = l);
                            var h = cc.v3(0, -830, 0),
                                g = 0,
                                y = h.y;
                            d.length > 1 && (0 == i && (g = h.x - 30), 1 == i && (g = h.x + 30)),
                                (a.node.getChildByName("bg").active = !1),
                                (a.node.getChildByName("tipsLine").active = !1),
                                cc
                                    .tween(a.node)
                                    .to(0.4, { x: g, y: y })
                                    .to(0.2, { position: h })
                                    .call(function () {
                                        if (i == d.length - 1) {
                                            var s = cc.instantiate(t.textPrefab);
                                            s.getComponent(p.default).init(t, e, o.text),
                                                s.getComponent(p.default).light(),
                                                t.tempTexts.addChild(s),
                                                s.setPosition(h),
                                                cc
                                                    .tween(s)
                                                    .delay(0.2)
                                                    .to(0.5, { position: n.position })
                                                    .call(function () {
                                                        n.getComponent(p.default).light(), s.destroy();
                                                    })
                                                    .start();
                                        }
                                        a.node.destroy();
                                    })
                                    .start();
                        },
                        f = this;
                    for (c = 0; c < d.length; c++) {
                        h(c);
                    }
                    return (
                        (this.totalBlockNum -= d.length),
                        this.currentTextNum--,
                        this.reloadSlot(-1),
                        this.totalBlockNum <= 0 && this.success(),
                        void (!this.useWenquxing &&
                            0 == this.indexUI.wenquBtn.active &&
                            this.currentTextNum / this.totalTextNum <= 0.8 &&
                            this.currentChapter > 0 &&
                            !r.default.hideWenqu &&
                            ((this.indexUI.wenquBtn.active = !0), this.sendEvent("showWenquXingBtn"))
                        )
                    );
                }
                this.currSlotNum >= this.gameConfig.slotNum && (r.default.unlimit || this.fail());
            }),
            (e.prototype.getBlockTypeIdxByType = function (t, e) {
                for (var o = 0; o < t.length; o++) {
                    if (t[o].type == e) return o;
                }
                return -1;
            }),
            (e.prototype.getBlockTypeByType = function (t, e) {
                for (var o = 0; o < t.length; o++) {
                    if (t[o].type == e) return o;
                }
                return -1;
            }),
            (e.prototype.getTextNodeByIdx = function (t) {
                for (var e = this.textsNode.children, o = 0; o < e.length; o++) {
                    var n = e[o];
                    if (n.getComponent(p.default).idx == t && 0 == n.getComponent(p.default).status) return n;
                }
            }),
            (e.prototype.showRankUI = function (t, e) {
                // var o = parseInt(e);
                // u.UIMgr.show(l.default.RankUI, {game: this, type: o}, !1);
            }),
            (e.prototype.showSettingsUI = function () {
                u.UIMgr.show(l.default.SettingsUI, this, !1);
            }),
            (e.prototype.showItemUI = function (t, e) {
                if (1 == e && this.useXiPai) this.indexUI.showTips(this.getLanguage("label_tips_item"));
                else {
                    if (2 == e) {
                        if (this.useCheHui) return void this.indexUI.showTips(this.getLanguage("label_tips_item"));
                        if (this.opHistory.length <= 0)
                            return void this.indexUI.showTips(this.getLanguage("label_item_2_err"));
                    }
                    if (3 == e) {
                        if (this.useYiChu) return void this.indexUI.showTips(this.getLanguage("label_tips_item"));
                        if (this.slotArea.length <= 0)
                            return void this.indexUI.showTips(this.getLanguage("label_item_3_err"));
                    }
                    if (4 == e && this.useShengShou) this.indexUI.showTips(this.getLanguage("label_tips_item"));
                    else {
                        if (5 == e && this.tipsCount > 0)
                            return (
                                this.tipsCount--,
                                this.tipsCount <= 0 ?
                                    ((this.tipsCount = 0), (this.tipsCountLabel.string = "+")) :
                                    (this.tipsCountLabel.string = this.tipsCount + ""),
                                c.default.showCustomAd(),
                                void this.tips()
                            );
                        if (6 == e) {
                            if (c.default.isWeb()) return void this.wenquxing();
                            if (this.useWenquxing)
                                return void this.indexUI.showTips(this.getLanguage("label_item_6_err"));
                        }
                        c.default.getRecorderTime() > 18e3 && c.default.stopRecorder(),
                            u.UIMgr.show(l.default.ItemUI, { game: this, type: e }, !1);
                    }
                }
            }),
            (e.prototype.backHome = function () {
                this.indexUI.showHome(),
                    (this._status = 0),
                    a.default.stopAllSound(),
                    a.default.isPlayingMusic() ||
                    1 != r.default.settings.music ||
                    a.default.playMusic(this.bgmMusic, !0);
            }),
            (e.prototype.shareGame = function () {
                c.default.share({ title: "这一关你肯定过不去，快来挑战一下。", query: "" });
            }),
            (e.prototype.showAlert = function (t) {
                u.UIMgr.show(l.default.AlertUI, { game: this, text: t });
            }),
            (e.prototype.showAlertFunc = function (t, e, o) {
                u.UIMgr.show(l.default.AlertUI, { game: this, text: t, cancel: o, func: e });
            }),
            (e.prototype.jumpToDy = function () {
                c.default.isTT() && (tt.openAwemeUserProfile(), this.sendEvent("jump_dy"));
            }),
            (e.prototype.addZhuoMian = function () {
                var t = this;
                c.default.isTT() &&
                    tt.addShortcut({
                        success: function success() {
                            t.sendEvent("add_zhuomian");
                        },
                        fail: function fail() { }
                    }),
                    c.default.isKS() &&
                    ks.saveAPKShortcut(function (t) {
                        -10005 === t.code || t.code;
                    });
            }),
            (e.prototype.showMoreGame = function () {
                "ios" !== tt.getSystemInfoSync().platform &&
                    tt.showMoreGamesModal({
                        appLaunchOptions: [],
                        success: function success(t) {
                            console.log("success", t.errMsg);
                        },
                        fail: function fail(t) {
                            console.log("fail", t.errMsg);
                        }
                    }),
                    this.sendEvent("more_game");
            }),
            (e.prototype.sendEvent = function (t) {
                var e = this.currentChapter + 1,
                    o = "C";
                e < 10 && (o += "00"),
                    e >= 10 && e < 100 && (o += "0"),
                    (o += e),
                    c.default.sendEvent({ key: t, value: { chapter: o } });
            }),
            (e.prototype.fuhuo = function () {
                (this._status = 1), (this.useFuhuo = !0), c.default.startRecorder(), this.yichu(!1);
            }),
            (e.prototype.restart = function () {
                this.sendEvent("restart"), this.initChapter();
            }),
            (e.prototype.showFailUI = function () {
                a.default.stopMucis(),
                    a.default.playSound(this.failMusic, !1),
                    u.UIMgr.show(l.default.FailUI, this, !1);
            }),
            (e.prototype.showFuHuoUI = function () {
                u.UIMgr.show(l.default.FuHuoUI, this, !1);
            }),
            (e.prototype.fail = function () {
                var t = this;
                1 == this._status &&
                    (c.default.vibrateLong(),
                        (this._status = 3),
                        this.indexUI.showTips(this.getLanguage("label_fail_tips")),
                        this.scheduleOnce(function () {
                            c.default.getRecorderTime() >= 18e3 && c.default.stopRecorder(),
                                t.sendEvent("fail"),
                                t.useFuhuo ? t.showFailUI() : t.showFuHuoUI();
                        }, 1.5));
            }),
            (e.prototype.success = function () {
                var t = this;
                if (
                    ((this._status = 2),
                        c.default.vibrateLong(),
                        r.default.complateLv(this.currentChapter),
                        0 == this.currentChapter)
                )
                    this.sendEvent("successOne"),
                        (this.gameWaitTime = 0),
                        (this.tipsWaitTime = 0),
                        (this.lastPopTime = new Date().getTime()),
                        this.scheduleOnce(function () {
                            t.currentChapter++, t.initChapter(), t.indexUI.showDiffcutNode();
                        }, 2);
                else {
                    if (!c.default.isWeb()) {
                        var e = {};
                        (e.platform = c.default.getPlatfrom()),
                            (e.platformDetail = c.default.getPlatFormDetail()),
                            (e.st = this.currentChapter),
                            c.default.getUserInfo({
                                success: function success(t) {
                                    var o = t.nickName,
                                        n = t.avatarUrl;
                                    (e.nickName = o),
                                        (e.avatar_url = n),
                                        (e.visitor = !1),
                                        c.default.sendHttpRequest(
                                            a.default.uploadScoreUrl,
                                            e,
                                            function () {
                                                console.log("上传战绩成功");
                                            },
                                            function () {
                                                console.log("上传战绩失败");
                                            }
                                        );
                                },
                                fail: function fail(t) {
                                    console.log("获取用户信息失败", t);
                                    var o = new Date(),
                                        n = "匿名用户" + o.getMonth() + o.getDate() + o.getSeconds();
                                    (e.nickName = n),
                                        (e.avatar_url = ""),
                                        (e.visitor = !0),
                                        c.default.sendHttpRequest(
                                            a.default.uploadScoreUrl,
                                            e,
                                            function () {
                                                console.log("上传战绩成功");
                                            },
                                            function () {
                                                console.log("上传战绩失败");
                                            }
                                        );
                                }
                            });
                    }
                    this.scheduleOnce(function () {
                        a.default.stopMucis(),
                            a.default.playSound(t.successMusic, !1),
                            c.default.getRecorderTime() >= 18e3 && c.default.stopRecorder(),
                            u.UIMgr.show(l.default.SuccessUI, t, !1),
                            t.sendEvent("success");
                    }, 2);
                }
            }),
            (e.prototype.getLanguage = function (t) {
                return this.languages.json[t][this.currentLanguages];
            }),
            (e.prototype.getLanguages = function (t) {
                return this.languages.json[t];
            }),
            (e.prototype.start = function () { }),
            (e.prototype.update = function (t) {
                var e = this;
                if (
                    1 == this._status &&
                    t < 1 &&
                    !this._zanting &&
                    ((this.gameTime += t),
                        (this.gameWaitTime += t),
                        (this.tipsScaleTime += t),
                        this.hasTips ||
                        ((this.tipsWaitTime += t),
                            this.tipsWaitTime >= this.tipsDurningTime &&
                            ((this.tipsWaitTime = 0),
                                this.currentChapter > 0 ?
                                    ((this.tipsDurningTime = 60), (this.hasTips = !0), this.tips()) :
                                    ((this.hasTips = !0), this.tips()))),
                        this.gameWaitTime > 10 &&
                        !this.tipsScale &&
                        this.tipsScaleTime >= 10 &&
                        ((this.tipsScale = !0),
                            (this.tipsScaleTime = 0),
                            cc
                                .tween(this.tipsBtn)
                                .to(0.2, { scale: 1.2 })
                                .to(0.2, { scale: 1 })
                                .to(0.2, { scale: 1.2 })
                                .to(0.2, { scale: 1 })
                                .call(function () {
                                    e.tipsScale = !1;
                                })
                                .start()),
                        this.gameWaitTime > 20 && this.currentChapter > 0)
                ) {
                    var o = new Date().getTime();
                    o - this.lastPopTime > 18e4 &&
                        (this.currentTextNum / this.totalTextNum < 0.7 ?
                            this.useWenquxing || c.default.isWeb() ?
                                this.useXiPai ?
                                    this.slotArea.length >= 5 && !this.useYiChu ?
                                        (this.showItemUI(null, 3), (this.lastPopTime = o), (this.gameWaitTime = 0)) :
                                        this.useShengShou ||
                                        (this.showItemUI(null, 4), (this.lastPopTime = o), (this.gameWaitTime = 0)) :
                                    (this.showItemUI(null, 1), (this.lastPopTime = o), (this.gameWaitTime = 0)) :
                                (this.showItemUI(null, 6), (this.lastPopTime = o), (this.gameWaitTime = 0)) :
                            this.slotArea.length >= 5 && !this.useYiChu ?
                                (this.showItemUI(null, 3), (this.lastPopTime = o), (this.gameWaitTime = 0)) :
                                this.tipsCount <= 0 ?
                                    (this.showItemUI(null, 5), (this.lastPopTime = o), (this.gameWaitTime = 0)) :
                                    this.useShengShou ||
                                    (this.showItemUI(null, 4), (this.lastPopTime = o), (this.gameWaitTime = 0)));
                }
            }),
            s([m(h.default)], e.prototype, "indexUI", void 0),
            s([m(cc.Label)], e.prototype, "lvLabel", void 0),
            s([m(cc.Node)], e.prototype, "shilingNode", void 0),
            s([m(cc.Node)], e.prototype, "itemsNode", void 0),
            s([m(cc.Node)], e.prototype, "slotNode", void 0),
            s([m(cc.Node)], e.prototype, "textsNode", void 0),
            s([m(cc.Node)], e.prototype, "textsBgNode", void 0),
            s([m(cc.Node)], e.prototype, "tempTexts", void 0),
            s([m(cc.Node)], e.prototype, "randomsNode", void 0),
            s([m(cc.Node)], e.prototype, "removesNode", void 0),
            s([m(cc.Label)], e.prototype, "tipsCountLabel", void 0),
            s([m(cc.Node)], e.prototype, "tipsBtn", void 0),
            s([m(cc.Node)], e.prototype, "topUI", void 0),
            s([m(cc.Prefab)], e.prototype, "blockItemPrefab", void 0),
            s([m(cc.Prefab)], e.prototype, "textPrefab", void 0),
            s([m(cc.JsonAsset)], e.prototype, "chapters", void 0),
            s([m(cc.JsonAsset)], e.prototype, "texts", void 0),
            s([m(cc.JsonAsset)], e.prototype, "languages", void 0),
            s([m(cc.AudioClip)], e.prototype, "bgmMusic", void 0),
            s([m(cc.AudioClip)], e.prototype, "successMusic", void 0),
            s([m(cc.AudioClip)], e.prototype, "failMusic", void 0),
            s([y], e)
        );
    })(cc.Component);
o.default = v;